home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-06-03 | 10.4 KB | 477 lines | [TEXT/MPS ] |
- /*************************************************************************************
- *
- * Object Oriented Shell
- *
- * WindowObj.cp - C Source
- *
- * Copyright © Apple Computer, Inc. 1988 - 1993
- * All rights reserved.
- *
- * This file defines the basic window functions. As it turns out, if you
- * (Yeah, I'm talkin' to you) pull out GWorldObj.cp (& the two sort algorithms)
- * and modify WindowObj.Link -- you could use the ENTIRE source code here
- * (Events, Windows, Traps, Main, etc) to support your own applications.
- * But I won't go into that here.
- *
- *************************************************************************************/
-
- #include "WindowObj.h"
- #include "main.h"
- #include "WindowObj.Link" // This is your interface file that defines your stuff
-
- // Initialize the global
- Boolean WindowObj::isColor = false;
-
- // NewWindowObj
- // This needs to be called immediately after the
- // obj *a = new obj;
- // As in:
- // a->NewWindowObj();
-
- Boolean WindowObj :: NewWindowObj( void)
- {
- Rect boundsRect;
-
-
-
- /* One of the neat things about the THINK C constructor is it fills the instance
- memory with zerøs which ensures that the variable "me" will be zerø upon startup */
- if( me == NIL) // Each object can only have 1 window
- { // Unless programmed otherwise...
- SetRect( &boundsRect, 40, 40, 500, 340);
-
- if( isColor == true)
- {
- me = NewCWindow( NIL, &boundsRect, (ConstStr255Param)"\pUntitled", true, 0, (WindowPtr)-1, true,
- /* CRITICALLY IMPORTANT:: */ (long) this);
- }
- else
- {
- me = NewWindow( NIL, // I have not declared a space for the window
- &boundsRect, // The boundary is 40,40, 140,140 in global coords
- (ConstStr255Param) "\pUntitled", // The title is "Untitled"
- true, // Make it visible
- 0, // DocumentProc type window (title, close, zoom, grow)
- (WindowPtr)-1, // Make it the front window
- true, // Give it a goAway box
- /* CRITICAL:: */ (long) this); // RefCon: Give it the address of this object!!
- }
- if( me != NIL)
- {
- SetPort( me);
- ((WindowPeek)me)->windowKind = WindowObjKind;
- }
- }
- if( me == nil)
- return false;
- else
- return true;
- }
-
-
- /***************************************************************************
-
- InitObj
-
- This function performs basic initialization that all of your windows can use.
- If you have any menus or other resources you want to load in at system start time,
- define a subordinant function of this and then call this function from inside it.
-
- ***************************************************************************/
- void WindowObj :: InitObj( void)
- {
- // char objName[32];
- // int fileRef;
- // int objNameLen;
-
- isColor = gMac.hasColorQD; // Retain the color bit
- useActivateClicks = false; // Do not interpret activate events as action events
- }
-
-
- Boolean WindowObj :: CloseWindowObj( void)
- {
- if( me != NIL) // You'll probably overide this code
- { // With your own that checks the dirtyFlag
- DisposeWindow( me); // Call the Mac to eliminate the window!
- me = NIL; // Take notice that the window is gone.
- }
- return true;
- }
-
-
- void WindowObj :: SetWindowTitle( Str255 *title)
- {
- SetWTitle( me, (ConstStr255Param)title);
- }
-
- void WindowObj :: IdleObj( void)
- {
- /* Do nothing during an Idle event ... */
- }
-
-
- /********************************************************************************
-
- AdjustMenus
-
- If there are any differences in the menu structure of a new Window Object,
- the new object must rewrite this code, there's just no way around it.
-
- However, I encourage authors to copy and paste these elements!!
- (That might help to speed the process.)
-
- ********************************************************************************/
-
- void WindowObj :: AdjustMenusObj( void)
- {
- MenuHandle menu;
-
- menu = GetMHandle( mFile); // Do the File menu first
- EnableItem(menu, iNew); // Enable the items, one at a time...
- EnableItem(menu, iOpen);
- if( me != NIL)
- {
- EnableItem(menu, iClose);
- EnableItem(menu, iSave);
- EnableItem(menu, iSaveAs);
- EnableItem(menu, iRevert);
- EnableItem(menu, iPageSetup);
- EnableItem(menu, iPrint);
- }
- else
- {
- DisableItem(menu, iClose);
- DisableItem(menu, iSave);
- DisableItem(menu, iSaveAs);
- DisableItem(menu, iRevert);
- DisableItem(menu, iPageSetup);
- DisableItem(menu, iPrint);
- }
- EnableItem(menu, iQuit);
-
- menu = GetMHandle( mEdit);
- DisableItem(menu, iUndo);
- DisableItem(menu, iCut);
- DisableItem(menu, iCopy);
- DisableItem(menu, iClear);
- DisableItem(menu, iPaste);
- }
-
-
- void WindowObj :: KeyPressObj( EventRecord *event)
- {
- int a = 0;
- if( a != 0)
- event->modifiers = 0;
- }
-
-
- void WindowObj :: MouseClickObj( EventRecord *event)
- {
- int a = 0;
- // Notice that the shell takes care of:
- // Dragging, zooming, tracking, etc.
- // This code only needs to worry about scroll bars,
- // other controls, and the content region!!
- if( a != 0)
- event->modifiers = 0;
- }
-
-
- void WindowObj :: UpdateObj( void)
- {
-
- #ifdef debugFlag
- DebugStr( "\pUpdate routine in WindowObj");
- #endif
- EraseRgn(me->visRgn); // By default, erase me... then redraw
- DrawObj(); // By default, updating is drawing... until you specify otherwise
- // But this algorithm is next to lame. So you'll probably want to
- // write your own UpdateObj() routine. Just as soon as
- // you get the rest of your App up and running!
- }
-
-
- void WindowObj :: DrawObj( void)
- {
-
- }
-
- void WindowObj :: PageSetupObj( void)
- {
- #ifdef debugFlag
- DebugStr( "\pPageSetupObj!!");
- #endif
- if( myPrintInfo == (void *)0 )
- {
- myPrintInfo = (THPrint) NewHandle( sizeof( TPrint));
- }
- PrOpen();
- PrStlDialog( myPrintInfo);
- PrClose();
- }
-
- void WindowObj :: PrintObj( void)
- {
- GrafPtr saveMe; // Save the "me" in the case that
- // the DrawCode changes GrafPtr's to "me"
- // P.S.: This ONLY works because WaitNextEvent
- // isn't ever called in the middle of
- // printing. Updating (a possible outcome
- // of W.N.E.) requires "me" to be set right!!
- TPPrPort myPrintPort;
-
- if( myPrintInfo == (void *)0 )
- {
- PageSetupObj();
- }
- PrOpen();
- if( PrJobDialog( myPrintInfo))
- {
- SetOutlinePreferred( true); // System 7.0 Support for TrueType
-
- myPrintPort = PrOpenDoc( myPrintInfo, (TPrPort *)0, (Ptr)0);
- if( PrError() == noErr)
- {
- saveMe = me;
- me = (GrafPtr) myPrintPort;
- PrOpenPage( myPrintPort, (Rect *)0);
- if( PrError() == noErr)
- {
- DrawObj();
- }
- PrClosePage( myPrintPort);
- }
- PrCloseDoc( myPrintPort);
- me = saveMe;
- }
- PrClose();
- }
-
- void WindowObj :: CutObj( EventRecord *event)
- {
- long int oserror;
- int a = 0;
- if( a != 0)
- event->modifiers = 0;
-
- oserror = ZeroScrap(); // Clear the deskScrap file
- }
-
- void WindowObj :: CopyObj( EventRecord *event)
- {
- long int oserror;
- int a = 0;
-
- if( a != 0)
- event->modifiers = 0;
-
- oserror = ZeroScrap(); // Clear the deskScrap file
- }
-
-
- void WindowObj :: PasteObj( EventRecord *event)
- {
- // No code because I don't know which TYPE the program wants
- int a = 0;
- if( a != 0)
- event->modifiers = 0;
- }
-
- void WindowObj :: UndoObj( EventRecord *event)
- {
- // Undo's need to be handled by the individual window
- int a = 0;
- if( a != 0)
- event->modifiers = 0;
- }
-
- void WindowObj :: DeleteObj( EventRecord *event)
- {
- int a = 0;
- if( a != 0)
- event->modifiers = 0;
- }
-
- void WindowObj :: ConvertScrapObj( void)
- {
- // Again, nothing here
- }
-
- void WindowObj :: ActivateObj( Boolean becomingActive)
- {
- if( becomingActive == true)
- {
- if( me != NIL)
- {
- SelectWindow( me);
- this->DrawGrowIconObj();
- }
- }
- }
-
-
- void WindowObj :: MenuObj( short menuID, short menuItem, EventRecord *event)
- {
- short b =0;
- WINDOWOBJ *a;
-
- if( b != 0)
- event->modifiers = 0;
-
- switch( menuID )
- {
- case mFile:
- switch( menuItem)
- {
- case iNew:
- a = new WINDOWOBJ;
- if( a)
- {
- a->me = (WindowPtr) 0;
- if( a->NewWindowObj() == false)
- delete a;
- }
- break;
- case iClose:
- CloseWindowObj();
- break;
- case iPageSetup:
- PageSetupObj();
- break;
- case iPrint:
- PrintObj();
- break;
- default:
- AppMenu( menuID, menuItem); // This is like inheritance!!
- break;
- }
- break;
-
- default:
- AppMenu( menuID, menuItem); // This is like inheritance!!
- break;
- }
- HiliteMenu(0);
- }
-
-
- void WindowObj :: AdjustCursorObj( Point mouseLoc, RgnHandle cursorRgn)
- {
- /* This routine doesn't use the mouseLocation, but your windows can! */
- if( cursorRgn != NIL) // From your window code, you can call AdjustCursor
- { // with NIL and this routine will simply adjust the cursor
- SetEmptyRgn( cursorRgn);// you should try incorporating it into your code, too.
- }
- SetCursor( &qd.arrow);
- if( mouseLoc.h == -5000)
- ;
- }
-
-
-
-
- void WindowObj :: DrawGrowIconObj( void)
- {
- WindowPtr copyMe = me;
-
- if( me != NIL)
- {
- DrawGrowIcon( me);
- }
- }
-
- void WindowObj :: DragWindowObj( EventRecord *event)
- {
- DragWindow( me, event->where, &qd.screenBits.bounds);
- }
-
-
- void WindowObj :: GrowWindowObj( EventRecord *event)
- {
- Rect growRect;
- long newSize;
-
- growRect = qd.screenBits.bounds;
- growRect.top = growRect.left = 80; /* Arbitrary minimum size */
- newSize = GrowWindow( me, event->where, &growRect);
- if( newSize != 0)
- {
- InvalidateScrollbars( me);
- SizeWindow( me, LoWrd(newSize), HiWrd(newSize), true);
- InvalidateScrollbars( me);
- }
- }
-
-
- void WindowObj :: ZoomWindowObj( EventRecord *event, Boolean OutIsTrue)
- {
- if( event->modifiers == 0x8000)
- OutIsTrue = true;
- }
-
-
- void WindowObj :: ScrollWindowObj( EventRecord *event)
- {
- if( event->modifiers == 0x8000)
- ;
- }
-
-
- void WindowObj :: DiskInsertObj( EventRecord *event)
- {
- Point aPoint = {100, 100};
- if( HiWrd(event->message) != noErr)
- {
- (void) DIBadMount(aPoint, event->message);
- }
- }
-
- short int WindowObj :: DrawingWidth( void)
- {
- if( me)
- {
- short int width = me->portRect.right - me->portRect.left;
- WindowPeek winObj = (WindowPeek)me;
- short int myKind = winObj -> windowKind;
-
- if( myKind == 0 || myKind == 8)
- return width - 16;
- else
- return width;
- }
- else
- return 0;
- }
-
- short int WindowObj :: DrawingHeight( void)
- {
- if( me)
- {
- short int height = me->portRect.bottom - me->portRect.top;
- WindowPeek winObj = (WindowPeek)me;
- short int myKind = winObj -> windowKind;
-
- if( myKind == 0 || myKind == 8)
- return height - 16;
- else
- return height;
- }
- else
- return 0;
- }
-
- void WindowObj :: DrawingRect( Rect *area)
- {
- if( me)
- {
- *area = me -> portRect;
- area->right = area->left + DrawingWidth();
- area->bottom = area->top + DrawingHeight();
- }
- else
- SetRect( area, 0, 0, 0, 0);
- }
-
-